package com.dqyt.khjc.service;

import com.dqyt.khjc.bean.DownFileBean;
import com.dqyt.khjc.config.Config;
import com.dqyt.khjc.mapper.DownFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.ServletOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.List;

/**
 * 下载文件
 */
@Service
public class DownloadFileService {

    @Autowired
    private DownFileMapper downFileMapper;

//    public boolean downloadFileService(){
//        try {
//            boolean isok = false;
//            List<DownFileBean> downFileBeans = downFileMapper.gerAllDownFile();
//            for (DownFileBean downFileBean : downFileBeans) {
//                //开始下载文件
//                String url = "http://cdthink.com/img/img_toukui.png";
//                URL u = new URL(url);
//                InputStream is = u.openStream();
//                OutputStream os = new FileOutputStream(Config.UPLOADFOLDER_LOCA+downFileBean.getFileUrl());
//                int buff = 0;
//                while ((buff = is.read()) != -1) {
//                    os.write(buff);
//                }
//                os.close();
//                is.close();
//                //下载成功之后删除数据库对应
//               downFileMapper.deleteDownFile(downFileBean.getFileId());
//            }
//            return isok;
//        }catch (Exception e){
//            return true;
//        }
//    }
}
